import { ShortcutsItem } from "../../shortcuts/ShortcutsItem";
import { CDItemData } from "../../../cache/CDItem/CDItemData";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { CopyConfig } from "../../../resource/CopyConfig";
import { CopySkillInfo } from "../../../resource/info/CopySkillInfo";
import { ItemData } from "../../../resource/info/ItemData";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { MsgManager } from "../../../manager/MsgManager";
import { SkillConfig } from "../../../resource/SkillConfig";
import { ESkillTargetType } from "../../../../../Message/Public/ESkillTargetType";
import { ESkillTargetNumber } from "../../../../../Message/Public/ESkillTargetNumber";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { CopyType } from "../CopyType";
import { GameProxy } from "../../../mvc/GameProxy";
import { SPoint } from "../../../../../Message/Public/SPoint";
import { DataEvent } from "../../../events/DataEvent";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { SceneRange } from "../../../scene/map/SceneRange";
import { Global } from "../../../../../com/gengine/global/Global";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GuideArrow } from "../../guide/GuideArrow";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class SixtySkillPropListPanel
    
    export  class SixtySkillPropListPanel /* flash.display.Sprite */
    {
        constructor(arg1: int=10)
        {
            
            this._skillVec = new Vector.<ShortcutsItem>();
            this._cdVec = new Vector.<CDItemData>();
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this._skillNum = arg1;
            this._commonCd = new CDItemData();
            this._commonCd.totalTime = 5000;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            LoaderManager.instance.load("SixtyCopySkillListBg.png", this.onBgLoaded);
            this.createSkillItems();
            var loc1=this._skillNum != 10 ? 439 * this._skillNum / 10 + 15 : 439;
            this._moveBtn = ObjCreate.createGButton("", loc1, 23, 24, 22, this, "MoveBtn2");
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(60088), "#FFFFFF");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            if (Cache.instance.clientSettingCache.isFirstCrossAryadevaSecretCopy) 
            {
                Dispatcher.addEventListener(EventName.CrossAryadevaSecretCopyRemoveGuideStepThirdly, this.removeGuide);
            }
            return;
        }

        /* internal  */onBgLoaded(arg1: ImageInfo): void
        {
            var loc1=new Object /* flash.display.Bitmap */(arg1.bitmapData);
            if (this._skillNum != 10) 
            {
                loc1.width = loc1.width * this._skillNum / 10 + 15;
            }
            this.addChildAt(loc1, 0);
            return;
        }

        /* internal  */createSkillItems(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            this._curCopyCode = Cache.instance.copy.copyInfo.code;
            var loc4=0;
            while (loc4 < this._skillNum) 
            {
                loc2 = new ShortcutsItem(loc4);
                loc2.x = 29 + loc4 * 41;
                loc2.y = 5;
                loc2.isDragAble = false;
                loc2.isDropAble = false;
                loc2.isThrowAble = false;
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClick);
                loc3 = CopyConfig.instance.getSkillInfoByCopyCodeAndPos(this._curCopyCode, loc4 + 1) as CopySkillInfo;
                if (loc3) 
                {
                    loc2.dragSource = new ItemData(loc3.itemCode);
                }
                loc1 = new CDItemData();
                loc1.totalTime = 5000;
                this.addChild(loc2);
                this._skillVec.push(loc2);
                this._cdVec.push(loc1);
                ++loc4;
            }
            this.updateSkillStatus();
            return;
        }

        /* internal  */onItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var scItem: ShortcutsItem;
            var onSuccess: Function;
            var skill: TSkill;
            var targets: Array<any>;

            var loc1;
            scItem = null;
            onSuccess = null;
            skill = null;
            targets = null;
            e = arg1;
            onSuccess = (arg1): void
            {
                var loc1=new CDItemData();
                loc1.totalTime = 5000;
                _cdVec[scItem.pos] = loc1;
                scItem.doCoolDown(_cdVec[scItem.pos], true);
                return;
            }
            scItem = e.target as ShortcutsItem;
            if (scItem.itemData && scItem.amount > 0) 
            {
                if (scItem.playingEffect) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(60090));
                }
                else 
                {
                    skill = SkillConfig.instance.getInfoByName(scItem.itemData.itemInfo.item.effect);
                    targets = [];
                    if (skill && skill.targetType == ESkillTargetType._ESkillTargetTypeEnemy && skill.targetNumber == ESkillTargetNumber._ESkillTargetNumberSingle) 
                    {
                        if (ThingUtil.selectEntity) 
                        {
                            targets.push(ThingUtil.selectEntity.entityInfo.entityInfo.entityId);
                        }
                        else 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(60089));
                            return;
                        }
                    }
                    this.startCommonCd();
                    var loc2=this._curCopyCode;
                    switch (loc2) 
                    {
                        case CopyType.SIXTY_COPY:
                        {
                            GameProxy.copy.sixtyCopyOperation(true, scItem.itemData.itemCode, targets, new SPoint(), onSuccess);
                            break;
                        }
                        case CopyType.CROSS_ARYADEVA_SECRET_COPY:
                        {
                            GameProxy.copy.useItemInCrossSecret(true, scItem.itemData.itemCode, targets, new SPoint(), onSuccess);
                            break;
                        }
                    }
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossAryadevaSecretCopyRemoveGuideStepThirdly));
            }
            return;
        }

        public startCommonCd(): void
        {
            this._commonCd.startCoolDown();
            var loc1=0;
            while (loc1 < this._skillVec.length) 
            {
                if (!this._skillVec[loc1].playingEffect) 
                {
                    this._cdVec[loc1] = this._commonCd;
                    this._skillVec[loc1].doCoolDown(this._commonCd, true);
                }
                ++loc1;
            }
            return;
        }

        public updateSkills(arg1: Array<any>): void
        {
            var loc1=false;
            var loc2=null;
            var loc4=0;
            var loc3=0;
            while (loc3 < this._skillNum) 
            {
                loc1 = false;
                loc4 = 0;
                while (loc4 < arg1.length) 
                {
                    loc2 = arg1[loc4] as ItemData;
                    if (this._skillVec[loc3].itemData && this._skillVec[loc3].itemData.itemCode == loc2.itemCode) 
                    {
                        loc1 = true;
                        this._skillVec[loc3].dragSource = loc2;
                        break;
                    }
                    ++loc4;
                }
                if (!loc1) 
                {
                    this._skillVec[loc3].amount = 0;
                }
                ++loc3;
            }
            this.updateSkillStatus();
            return;
        }

        public getSkillPropPointByCode(arg1: int): Object /* flash.geom.Point */
        {
            var loc1=0;
            while (loc1 < this._skillVec.length) 
            {
                if (this._skillVec[loc1].itemData && this._skillVec[loc1].itemData.itemCode == arg1) 
                {
                    return this.localToGlobal(new Object /* flash.geom.Point */(this._skillVec[loc1].x, this._skillVec[loc1].y));
                }
                ++loc1;
            }
            return new Object /* flash.geom.Point */();
        }

        /* internal  */updateSkillStatus(): void
        {
            var loc1=0;
            while (loc1 < this._skillNum) 
            {
                this._skillVec[loc1].doCoolDown(this._cdVec[loc1]);
                if (this._skillVec[loc1].amount > 0) 
                {
                    this._skillVec[loc1].filters = [];
                }
                else 
                {
                    this._skillVec[loc1].setAmountText(-1);
                    this._skillVec[loc1].filters = [FilterConst.colorFilter];
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 100;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public addGuide(): void
        {
            this._guideArrow = GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_L);
            this._guideArrow.x = 79;
            this._guideArrow.y = 27;
            this.addChild(this._guideArrow);
            return;
        }

        /* internal  */removeGuide(arg1: DataEvent): void
        {
            if (this._guideArrow && this._guideArrow.parent) 
            {
                this._guideArrow.parent.removeChild(this._guideArrow);
                this._guideArrow = null;
            }
            return;
        }

        /* internal */ /* var */_skillVec: Vector.<ShortcutsItem>;

        /* internal */ /* var */_cdVec: Vector.<CDItemData>;

        /* internal */ /* var */_moveRec: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_commonCd: CDItemData;

        /* internal */ /* var */_curCopyCode: int;

        /* internal */ /* var */_skillNum: int;

        /* internal */ /* var */_guideArrow: GuideArrow;
    }
